import java.awt.Point;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import com.speljohan.rsbot.script.Calculations;
import com.speljohan.rsbot.script.Constants;
import com.speljohan.rsbot.script.Script;
import com.speljohan.rsbot.script.wrappers.RSInterface;
import com.speljohan.rsbot.script.wrappers.RSItemTile;
import com.speljohan.rsbot.script.wrappers.RSNPC;
import com.speljohan.rsbot.script.wrappers.RSObject;
import com.speljohan.rsbot.script.wrappers.RSTile;

public class MysticAZombies extends Script {

	public MysticAZombies() {
		super();
		setParameter("author", "Mouchicc - Mystic Team");
		setParameter("version", "1.0");
		setParameter("name", "MysticAZombies");
		setParameter("category", "Combat");
	}

	// Booleans:
	boolean prayedUp = false;
	boolean ranging = false;
	boolean B2P = false;
	boolean Piety = false;
	boolean Chivalry = false;
	boolean MysticMight = false;
	boolean EagleEye = false;
	boolean UltimateStrength = false;
	boolean IncredibleReflexes = false;
	boolean spec = false;
	boolean Guthan = false;
	boolean UseDDS = false;
	boolean doingspec;
	boolean potion;
	boolean charmpickup;
	boolean takeSomeItem;

	// Ints & Longs:
	public int itemIndex;
	public int ITPID1 = 0000;
	public int ITPID2 = 0000;
	public int[] ITPIDs;
	public static int[] potID;
	public int[] charms = { 12158, 12159, 12160, 12163 };
	int switchAt = (skills.getCurrentSkillLevel(STAT_HITPOINTS) / 100) * 75;
	public int tabID = 8015; // Bones2Peaches
	public int[] peach = { 6883, 1971, 1969 }; // Peach
	int eatAT;
	int switchBack;

	int Orighelm;
	int Origcape;
	int Origamulet;
	int Origweapon;
	int Origbody;
	int Origshield;
	int Origlegs;
	int Origgloves;
	int Origboots;
	int Origring;
	int Origarrows;
	int Bones = 526;
	public int fightMode;
	int prayState;

	int levelsGained;
	int curStatExp;
	int startLvl;
	int startExp;
	int stat;
	int startxp;
	long lvls = 0;
	int startLVL;
	int CurSTAT;
	int RealSTAT;
	long startTime = System.currentTimeMillis();
	public int ITWID1 = 0000;
	public int ITWID2 = 0000;
	public int[] ITWIDs;
	int runEnergy = random(25, 60);

	// Others:
	RSNPC Banker = getNearestNPCByID(6538);
	RSNPC AZombies = getNearestNPCByID(8149, 8150, 8151, 8152, 8153);
	private static RSTile current = new RSTile(0, 0);
	RSObject ladderDown = getNearestObjectByID(39190);
	RSObject ladderUp = getNearestObjectByID(39191);
	RSTile Altar = new RSTile(3240, 3608);

	public static int[] FoodID = { 1895, 1893, 1891, 4293, 2142, 291, 2140,
			3228, 9980, 7223, 6297, 6293, 6295, 6299, 7521, 9988, 7228, 2878,
			7568, 2343, 1861, 13433, 315, 325, 319, 3144, 347, 355, 333, 339,
			351, 329, 3381, 361, 379, 380, 10136, 5003, 379, 365, 373, 374,
			7946, 385, 397, 391, 3369, 3371, 3373, 2309, 2325, 2333, 2327,
			2331, 2323, 2335, 7178, 7180, 7188, 7190, 7198, 7200, 7208, 7210,
			7218, 7220, 2003, 2011, 2289, 2291, 2293, 2295, 2297, 2299, 2301,
			2303, 1891, 1893, 1895, 1897, 1898, 1899, 1900, 1901, 1902, 7072,
			7062, 7078, 7064, 7084, 7082, 7066, 7068, 1942, 6701, 6703, 7054,
			6705, 7056, 7060, 2130, 1985, 1993, 1989, 1978, 5763, 5765, 1913,
			5747, 1905, 5739, 1909, 5743, 1907, 1911, 5745, 2955, 5749, 5751,
			5753, 5755, 5757, 5759, 5761, 2084, 2034, 2048, 2036, 2217, 2213,
			2205, 2209, 2054, 2040, 2080, 2277, 2225, 2255, 2221, 2253, 2219,
			2281, 2227, 2223, 2191, 2233, 2092, 2032, 2074, 2030, 2281, 2235,
			2064, 2028, 2187, 2185, 2229, 6883, 1971, 4608, 1883, 1885 };

	// ***Other***\\
	String skill;

	public int[] GuthanSpears = new int[] { 4910, 4911, 4912, 4913 };
	public int GuthanHelm = 4916;
	public int GuthanBody = 4922;
	public int GuthanLegs = 4904;

	public int[] GuthanArmour = { GuthanHelm, GuthanBody, GuthanLegs, 4910,
			4911, 4912, 4913 };
	int yourPray;

	RSTile[] toAZombies = { new RSTile(3191, 3676), new RSTile(3193, 3659),
			new RSTile(3202, 3647), new RSTile(3206, 3630),
			new RSTile(3223, 3633), new RSTile(3236, 3622),
			new RSTile(3239, 3605) };

	public String getName() {
		return "MysticAZombies";
	}

	public String getAuthor() {
		return "Mouchicc - Mystic Team";
	}

	public String getScriptCategory() {
		return "Combat";
	}

	public double getVersion() {
		return 1.0;
	}

	@Override
	public String getScriptDescription() {
		String html = "";
		html += "<html>";
		html += "<head>";
		html += "<style type=\"text/css\"> hr {color: white} p {margin-left: 20px}</style>";
		html += "</head>";
		html += "<body>";
		html += "<center>";
		html += "<b><font size=\"6\" color=\"red\">" + getName() + " v"
				+ getVersion() + " M" + "</font></b><br>";
		html += "<font size=\"3\" color=\"red\">Please start @ the eastern Crabs.<br></font>";
		html += "<center><table border=\"0\"><tr><td colspan=\"5\"><center><font size=6><b>== Options and Settings ==</b></font></center></td></tr><tr><td colspan=4><hr></td></tr><tbody><tr><td width=\"135\">";
		html += "<b>Use Special:</b></td><td width=\"140\"><center><input type=\"checkbox\" name=\"spec\" value=\"true\"></center></td><td width=\"135\"></b></center></td></tr>";
		html += "<b><td>Use Potions:</b></td><td width=\"140\"><center><input type=\"checkbox\" name=\"pot\" value=\"true\"></center></td><td width=\"135\"></b></center></td></tr>";
		html += "<b><td>Pick Charms:</b></td><td width=\"140\"><center><input type=\"checkbox\" name=\"charm\" value=\"true\"></center></td><td width=\"135\"></b></center></td></tr>";
		html += "<tr><td><b>Eat At:</b>&nbsp<input type=\"text\" name=\"eatt\" size=\"4\"</center></td></tr>";
		html += "<b><td>Attack Style:</b></td><td width=\"140\"><center><select name=\"skill\"><option>Strength<option>Attack<option>Defence<option>Rapid Ranged<option>Accurate Ranged<option>Longrange Ranged</select></center></td><td width=\"135\"></b></center></td></tr>";
		html += "<tr><td><b>Pick Item ID:</b></td><td colspan=\"3\"><center><b>Item ID 1:</b>&nbsp<input type=\"text\" name=\"ItemID1\" size=\"4\">&nbsp&nbsp<b>Item ID 2:</b>&nbsp<input type=\"text\" name=\"ItemID2\" size=\"4\"></center></td></tr>";
		html += "<tr><td><b>Pick Item Name:</b></td><td colspan=\"3\"><center><b>Item name 1:</b>&nbsp<input type=\"text\" name=\"ItemN1\" size=\"10\">&nbsp&nbsp<b>Item name 2:</b>&nbsp<input type=\"text\" name=\"ItemN2\" size=\"10\"></center></td></tr>";
		html += "</body>n";
		html += "</html>";
		return (html);
	}

	// What to load on Start
	@Override
	public boolean onStart(Map<String, String> args) {
		log("************************************************");
		log("********MysticGSpiderAFKer V" + getVersion() + " started!********");
		log("*********Let's get some Experience**************");
		log("************************************************");
		startLVL = skills.getCurrentSkillLevel(stat);
		yourPray = (skills.getCurrentSkillLevel(STAT_PRAYER) / 100) * 70;

		Orighelm = getEquipmentArray()[0];
		Origweapon = getEquipmentArray()[3];
		Origbody = getEquipmentArray()[4];
		Origshield = getEquipmentArray()[5];
		Origlegs = getEquipmentArray()[7];
		Origarrows = getEquipmentArray()[13];

		if (args.get("spec") != null) {
			doingspec = true;
		} else {
			doingspec = false;
		}
		if (args.get("pot") != null) {
			potion = true;
		} else {
			potion = false;
		}
		if (args.get("skill").equals("Attack")) {
			stat = STAT_ATTACK;
			skill = "Attack";
			fightMode = 0;
			potID = new int[] { 121, 122, 123, 124, 125, 126, 145, 146, 147,
					148, 149, 150, 2428, 2429, 2436, 2437, 11429, 11430, 11431,
					11432, 9739, 9740, 9741, 9742, 9743, 9744, 9745, 9746 };
		}
		if (args.get("skill").equals("Strength")) {
			stat = STAT_STRENGTH;
			skill = "Strength";
			fightMode = 1;
			potID = new int[] { 113, 114, 115, 116, 117, 118, 119, 120, 157,
					158, 159, 160, 161, 162, 2440, 2441, 11441, 11442, 11443,
					11444, 9739, 9740, 9741, 9742, 9743, 9744, 9745, 9746 };

		}
		if (args.get("skill").equals("Defence")) {
			stat = STAT_DEFENSE;
			skill = "Defence";
			fightMode = 3;
			potID = new int[] { 133, 134, 135, 136, 137, 138, 163, 164, 165,
					166, 167, 168, 2432, 2433, 2442, 2443, 11457, 11458, 11459,
					11460, 9739, 9740, 9741, 9742, 9743, 9744, 9745, 9746 };
		}
		if (args.get("skill").equals("Accurate Ranged")) {
			stat = STAT_RANGE;
			skill = "Ranged";
			fightMode = 0;
			potID = new int[] { 169, 170, 171, 172, 173, 174, 2444, 2445,
					11509, 11510, 11511, 11512 };
		}
		if (args.get("skill").equals("Rapid Ranged")) {
			stat = STAT_RANGE;
			skill = "Ranged";
			fightMode = 1;
			potID = new int[] { 169, 170, 171, 172, 173, 174, 2444, 2445,
					11509, 11510, 11511, 11512 };
		}
		if (args.get("skill").equals("Longrange Ranged")) {
			stat = STAT_RANGE;
			skill = "Ranged";
			fightMode = 3;
			potID = new int[] { 169, 170, 171, 172, 173, 174, 2444, 2445,
					11509, 11510, 11511, 11512 };
		}
		return true;
	}

	// What to do when finished
	public void onFinish() {
		log("Thanks for using the script!");
		log("XP per hour: "
				+ ((skills.getCurrentSkillExp(stat) - startExp) * (3600000D / (((double) System
						.currentTimeMillis() - (double) startTime)))));
		log("Levels Gained: " + lvls);
		log("Experience Gained: "
				+ (skills.getCurrentSkillExp(stat) - startExp));
	}

	// Does Special!
	public void doSpec() {
		if (getSpec() >= 1000 && !specEnabled() && doingspec == true) {
			openTab(Constants.TAB_ATTACK);
			clickMouse(645 + random(0, 4), 425 + random(0, 4), true);
			wait(350);
		}
		return;
	}

	public void useDDS() {
		int DDS = 5698;
		if (equipmentContainsAny(DDS)) {
			if (getCurrentTab() != TAB_ATTACK) {
				openTab(TAB_ATTACK);
			}
			wait(random(600, 1200));
			try {
				if (getSpec() >= 1000 && !specEnabled() && UseDDS == true) {
					openTab(Constants.TAB_ATTACK);
					clickMouse(645 + random(0, 4), 425 + random(0, 4), true);
					wait(400);
					clickMouse(645 + random(0, 4), 425 + random(0, 4), true);
					wait(400);
					clickMouse(645 + random(0, 4), 425 + random(0, 4), true);
					wait(400);
					clickMouse(645 + random(0, 4), 425 + random(0, 4), true);
					wait(400);
				}
			} catch (Exception e) {

			}
		} else {
			clickInventoryItem(DDS, "Wield");
		}
		return;
	}

	public void GuthanOn() {
		if (inventoryContainsAny(GuthanArmour)) {
			if (getCurrentTab() != TAB_INVENTORY) {
				openTab(TAB_INVENTORY);
			}
			wait(random(600, 1200));
			try {
				openTab(Constants.TAB_INVENTORY);
				clickInventoryItem(GuthanHelm, "Wear");
				wait(400);
				clickInventoryItem(GuthanBody, "Wear");
				wait(400);
				clickInventoryItem(GuthanLegs, "Wear");
				wait(400);
				for (int i = 0; i < GuthanSpears.length; i++) {
					clickInventoryItem(GuthanSpears[i], "Wear");
				}
				wait(400);
			} catch (Exception e) {

			}
		}
		return;
	}

	public void OrigArmourOn() {
		if (inventoryContainsAny(Orighelm, Origweapon, Origbody, Origshield,
				Origlegs)) {
			if (getCurrentTab() != TAB_INVENTORY) {
				openTab(TAB_INVENTORY);
			}
			wait(random(600, 1200));
			try {
				openTab(Constants.TAB_INVENTORY);
				clickInventoryItem(Orighelm, "Wear");
				wait(400);
				clickInventoryItem(Origshield, "Wear");
				wait(400);
				clickInventoryItem(Origbody, "Wear");
				wait(400);
				clickInventoryItem(Origlegs, "Wear");
				wait(400);
				clickInventoryItem(Origweapon, "Wear");
				wait(400);
			} catch (Exception e) {

			}
		}
		return;
	}

	public void activatePrayer() {
		if (getCurrentTab() != TAB_PRAYER) {
			openTab(TAB_PRAYER);
		}
		if (Piety) {
			log("Piety Activated!");
			atInterface(RSInterface.getInterface(271).getChild(57));
			wait(random(200, 500));
		}
		if (Chivalry) {
			log("Chivalry Activated!");
			atInterface(RSInterface.getInterface(271).getChild(55));
			wait(random(200, 500));
		}
		if (MysticMight) {
			log("Mystic Might Activated!");
			atInterface(RSInterface.getInterface(271).getChild(45));
			wait(random(200, 500));
		}
		if (EagleEye) {
			log("Eagle Eye Activated!");
			atInterface(RSInterface.getInterface(271).getChild(43));
			wait(random(200, 500));
		}
		if (IncredibleReflexes) {
			log("Incredible Reflexes Activated!");
			atInterface(RSInterface.getInterface(271).getChild(35));
			wait(random(200, 500));
		}
		if (UltimateStrength) {
			log("Ultimate Strength Activated!");
			atInterface(RSInterface.getInterface(271).getChild(33));
			wait(random(200, 500));
		}
	}

	// Easy method for eating
	private void check_and_eat() {
		int MyHP = skills.getCurrentSkillLevel(STAT_HITPOINTS);
		if (MyHP <= eatAT && inventoryContains(FoodID)) {
			int[] items = getInventoryArray();
			for (int i = 0; i < FoodID.length; i++) {
				if (items[i] == FoodID[i]) {
					if (getInventoryCount(FoodID[i]) >= 1) {
						clickInventoryItem(FoodID[i], "Eat");
					}
				}
			}
		}
	}

	public void RangeIt() {
		if (ranging == true) {
			int Arrowz = getEquipmentArray()[13];
			RSTile pickArrows = getGroundItemByID(Arrowz);
			if (getInventoryCount(Arrowz) > random(80, 130)) {
				clickInventoryItem(Arrowz, "Wield");
			}

			if (pickArrows != null && getMyPlayer().getInteracting() == null
					&& !getMyPlayer().isMoving() && distanceTo(pickArrows) <= 2) {
				clickTile(pickArrows, "Take ");
				wait(random(300, 850));
			}
		}
	}

	private boolean inventoryContainsAny(int... items) {
		for (int item : getInventoryArray())
			for (int id : items)
				if (item == id)
					return true;
		return false;
	}

	private boolean equipmentContainsAny(int... items) {
		for (int item : getEquipmentArray())
			for (int id : items)
				if (item == id)
					return true;
		return false;
	}

	// Gets Special
	public int getSpec() {
		return getSetting(300);
	}

	// Gets if Special is Enabled
	public boolean specEnabled() {
		return (getSetting(301)) == 1;
	}

	public void B2P() {
		if (skills.getCurrentSkillLevel(3) <= eatAT + random(-3, 5)) {
			log("Food time");
			if (getInventoryCount(peach) >= 1) {
				for (int i = 0; i < peach.length; i++) {
					clickInventoryItem(peach[i], "Eat");
					wait(random(100, 500));
				}
			} else {
				log("Emergency tab time");
				clickInventoryItem(tabID, "break");
				wait(random(2000, 3000));
			}
			int bones = 526;
			if (getInventoryCount(bones) >= 20) {
				if (getInventoryCount(tabID) >= 1) {
					clickInventoryItem(tabID, "break");
					log("Made more peaches");
					wait(random(2000, 3000));
				} else {
					log("We are out of tablets!");
					wait(5000);
					stopAllScripts();
				}
			}
		}
	}

	public void drinkIt() {
		int CurSTAT = skills.getCurrentSkillLevel(stat);
		int RealSTAT = skills.getRealSkillLevel(stat);
		if (CurSTAT - RealSTAT <= random(1, 2) && potion == true) {
			for (int i = 0; i < potID.length; i++) {
				clickInventoryItem(potID[i], "Drink");
				return;
			}
		} else {
			wait(random(20, 30));
			return;
		}
	}

	public boolean getPrayUp() {
		RSTile upTile = ladderUp.getLocation();
		RSTile downTile = ladderDown.getLocation();

		if (tileOnScreen(upTile)) {
			clickTile(upTile, "Up");
			prayState = 1;
		}

		if (prayState == 1) {
			clickTile(Altar, "Pray");
			prayState = 2;
		}

		if (prayState == 2) {
			clickTile(downTile, "Down");
			prayState = 3;
		}

		if (prayState == 3) {
			prayedUp = true;
		}

		return false;
	}

	// Takes Charms
	public void takeCharms() {
		final RSTile charmItems = getGroundItemByID(charms);
		if (charmpickup) {
			if (charmItems != null && getMyPlayer().getInteracting() == null
					&& !getMyPlayer().isMoving() && distanceTo(charmItems) <= 2) {
				clickTile(charmItems, "charm");
				wait(random(300, 850));
			}
		}
		return;
	}

	// Takes Item
	public void takeCustomItem() {
		final RSItemTile someCustomItem = getGroundItemByID(ITPIDs);
		if (takeSomeItem) {
			if (someCustomItem != null
					&& getMyPlayer().getInteracting() == null
					&& !getMyPlayer().isMoving()
					&& distanceTo(someCustomItem) <= 2) {
				clickTile(someCustomItem, "Take ");
				wait(random(300, 850));
			}
		}
		return;
	}

	private enum Action {
		Eat, TakeCharms, TakeItems, GuthanOn, OrigArmourOn, B2P, PrayUp, Potion, AttackNPC, UseDDS, Wait
	};

	private Action getAction() {
		try {
			RSTile charmItems = getGroundItemByID(charms);
			RSItemTile someCustomItem = getGroundItemByID(ITPIDs);
			int MyHP = skills.getCurrentSkillLevel(STAT_HITPOINTS);

			if (MyHP <= eatAT + random(-3, 5)) {
				if (!B2P) {
					return Action.Eat;
				} else if (B2P) {
					return Action.B2P;
				}
			}

			if (charmpickup && charmItems != null) {
				return Action.TakeCharms;
			}

			if (takeSomeItem && someCustomItem != null) {
				return Action.TakeItems;
			}

			if (skills.getCurrentSkillLevel(3) <= switchAt && Guthan == true) {
				return Action.GuthanOn;
			}

			if (skills.getCurrentSkillLevel(3) >= switchBack && Guthan == true) {
				return Action.OrigArmourOn;
			}

			if (skills.getCurrentSkillLevel(STAT_PRAYER) <= yourPray
					&& !prayedUp) {
				return Action.PrayUp;
			}

			if (potion && inventoryContains(potID)) {
				return Action.Potion;
			}

			if (AZombies != null && getMyPlayer().getAnimation() == -1
					&& getMyPlayer().getInteracting() == null) {
				long timeNow = System.currentTimeMillis();
				if (timeNow >= random(2000, 4000)) {
					return Action.AttackNPC;
				}
			}

			if (UseDDS) {
				return Action.UseDDS;
			}

		} catch (final Exception e) {
			e.printStackTrace();
		}

		return Action.Wait;
	}

	@Override
	public int loop() {

		if (getMyPlayer().isMoving()) {
			return random(800, 1600);
		}

		while (canContinue()) {
			clickContinue();
		}

		if (!isRunning() && getEnergy() > runEnergy) {
			setRun(true);
		}

		doSpec();

		if (ranging) {
			RangeIt();
		}

		try {
			final Action action = getAction();
			if (action != null) {
				switch (action) {
				case Eat:
					check_and_eat();
					break;

				case TakeCharms:
					takeCharms();
					break;

				case TakeItems:
					takeCustomItem();
					break;

				case GuthanOn:
					GuthanOn();
					break;

				case OrigArmourOn:
					OrigArmourOn();
					break;

				case B2P:
					RSItemTile bones = getGroundItemByID(526);
					if (bones != null && !isInventoryFull()) {
						atTile(bones, "Take Bones");
						wait(random(800, 900));
					}
					if (getInventoryCount(Bones) >= 21) {
						B2P();
					}
					break;

				case PrayUp:
					getPrayUp();
					break;

				case Potion:
					drinkIt();
					break;

				case AttackNPC:
					clickNPC(AZombies, "attack");
					break;
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return random(150, 200);
	}

	// Clicks a NPC by Ruski
	public boolean clickNPC(RSNPC npc, String action) {
		if (npc == null) {
			return false;
		}
		RSTile tile = npc.getLocation();
		if (!tile.isValid()) {
			return false;
		}

		try {
			Point screenLoc = npc.getScreenLocation();
			if (distanceTo(tile) > 6 || !pointOnScreen(screenLoc)) {
				turnToTile(tile);
			}
			for (int i = 0; i < 12; i++) {
				screenLoc = npc.getScreenLocation();
				if (!npc.isValid() || !pointOnScreen(screenLoc)) {
					return false;
				}
				moveMouse(screenLoc, 5, 5);
				if (getMenuItems().get(0).toLowerCase().contains(
						npc.getName().toLowerCase())) {
					break;
				}
				if (getMouseLocation().equals(screenLoc)) {
					break;
				}
			}
			List<String> menuItems = getMenuItems();
			if (menuItems.isEmpty()) {
				return false;
			}
			for (int a = 0; a < menuItems.size(); a++) {
				if (menuItems.get(a).toLowerCase().contains(
						npc.getName().toLowerCase())) {
					if (menuItems.get(0).toLowerCase().contains(
							action.toLowerCase())) {
						clickMouse(true);
						return true;
					} else {
						clickMouse(false);
						return atMenu(action);
					}
				}
			}
		} catch (Exception e) {
			System.out.print("clickNPC(RSNPC, String) error: " + e);
			return false;
		}
		return false;
	}

	// clickTile method by DDM
	public boolean clickTile(RSTile tile, String option) {
		Point p = Calculations.tileToScreen(tile);
		p.x += random(-5, 6);
		p.y += random(-5, 6);
		if (p.x < 0 || p.y < 0) {
			return false;
		}
		moveMouse(p);
		// wait(random(100,150));
		getMenuItems();
		@SuppressWarnings("unused")
		List<String> itemsList = getMenuItems();

		long waitTime = System.currentTimeMillis() + random(50, 250);
		boolean foundOption = false;
		while (System.currentTimeMillis() < waitTime && !foundOption) {
			wait(15);
			foundOption = (itemsList = getMenuItems()).get(0).toLowerCase()
					.contains(option.toLowerCase());
		}
		if (foundOption) {
			clickMouse(true);
			wait(random(150, 300));
			return true;
		}
		clickMouse(false);
		wait(random(150, 300));
		return atMenu(option);
	}

	public boolean walkPathOnScreenAndMM(final RSTile[] path, final int maxDist) {
		try {
			final RSTile next = nextTile(path, maxDist);
			if (next != null && !next.equals(current)) {
				if (tileOnScreen(next)) {
					atTile(next, "alk");
				} else {
					walkTileMM(next);
				}
				current = next;
				return false;
			} else if (next != null && next.equals(current)) {
				return false;
			}
		} catch (final Exception e) {
			log("walkPathOnScreen() error: " + e.getMessage());
			return false;
		}
		return true;
	}

	// Method for clicking an inventoryItem
	public boolean clickInventoryItem(int itemID, String option) {
		if (getCurrentTab() != TAB_INVENTORY) {
			openTab(TAB_INVENTORY);
		}
		int[] items = getInventoryArray();
		java.util.List<Integer> possible = new ArrayList<Integer>();
		for (int i = 0; i < items.length; i++) {
			if (items[i] == itemID) {
				possible.add(i);
			}
		}
		if (possible.size() == 0) {
			return false;
		}
		int idx = possible.get(random(0, possible.size()));
		Point t = getInventoryItemPoint(idx);
		moveMouse(t, 5, 5);
		long waitTime = System.currentTimeMillis() + random(50, 250);
		boolean found = false;
		while (!found && System.currentTimeMillis() < waitTime) {
			wait(15);
			if ((getMenuItems()).get(0).toLowerCase().contains(
					option.toLowerCase())) {
				found = true;
			}
		}
		if (found) {
			clickMouse(true);
			wait(random(150, 250));
			return true;
		}
		clickMouse(false);
		wait(random(150, 250));
		return atMenu(option);
	}
}
